﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using System.Configuration;
using TGIApp.Model;

namespace TGIApp.Web.Controllers
{
    public class EventController : Controller
    {
        //
        // GET: /Event/

        public ActionResult Index()
        {
            var proxy = new Proxy.ServiceProxy();
            var events = proxy.GetAllEvents();
            return View(events);
        }

        //
        // GET: /Event/Details/5

        public ActionResult Details(int id)
        {
            var proxy = new Proxy.ServiceProxy();
            var evnt = proxy.GetEventById(id);
            return View(evnt);
        }

        //
        // GET: /Event/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Event/Create

        [HttpPost]
        public ActionResult Create(Event evnt)
        {
            if (ModelState.IsValid)
            {
                ITgiService proxy = new Proxy.ServiceProxy();
                proxy.CreateEvent(evnt);
            }
            return RedirectToAction("Index");
        }

        //
        // GET: /Event/Edit/5

        public ActionResult Edit(int id)
        {
            ITgiService proxy = new Proxy.ServiceProxy();
            var evnt = proxy.GetEventById(id);
            return View(evnt);
        }

        //
        // POST: /Event/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, Event evnt)
        {
            if (ModelState.IsValid)
            {
                ITgiService proxy = new Proxy.ServiceProxy();
                proxy.UpdateEvent(evnt);
            }
            return RedirectToAction("Index");
        }

        //
        // GET: /Event/Delete/5

        public ActionResult Delete(int id)
        {
            ITgiService proxy = new Proxy.ServiceProxy();
            var evnt = proxy.GetEventById(id);
            return View(evnt);
        }

        //
        // POST: /Event/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, Event evnt)
        {

            ITgiService proxy = new Proxy.ServiceProxy();
            proxy.DeleteEventById(id);
            return RedirectToAction("Index");
        }
    }
}
